package com.niit.listviewsimpleadapter;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    ArrayList<Map<String,Object>> tempData;
    ListView myListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.activity_main);
        findViews();
    }
    private void findViews() {
        tempData = getData();
        myListView = new ListView(this);
        SimpleAdapter myAdapter = new SimpleAdapter(this,tempData,R.layout.activity_main,
                new String[]{"image","title","info"},new int[]{R.id.image,R.id.title,R.id.info});
        myListView.setAdapter(myAdapter);
        setContentView(myListView);
    }

    private ArrayList<Map<String,Object>> getData(){
        ArrayList<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("image",R.drawable.class1);
        map.put("title","嵌入式课程");
        map.put("info","基础课程");
        list.add(map);
        Map<String,Object> map1 = new HashMap<String,Object>();
        map1.put("image",R.drawable.class2);
        map1.put("title","C语言课程");
        map1.put("info","基础语言");
        list.add(map1);
        Map<String,Object> map2 = new HashMap<String,Object>();
        map2.put("image",R.drawable.class3);
        map2.put("title","Java课程");
        map2.put("info","基础语言");
        list.add(map2);
        Map<String,Object> map3 = new HashMap<String,Object>();
        map3.put("image",R.drawable.class4);
        map3.put("title","Android课程");
        map3.put("info","移动开发核心课程");
        list.add(map3);
        return list;
    }

      /*  myList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            }
        });*/
}

